package org.usmile.algorithms.huawei.acm;

import java.util.Scanner;

// https://blog.csdn.net/qq_34465338/article/details/128369003
public class _计算至少需要多少个快递主站点 {
    private static int[] parent;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        parent = new int[n];
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
        sc.nextLine();
        int[][] metric = new int[n][n];
        for(int row = 0; row < n; row++) {
            for (int col = 0; col < n; col ++) {
                metric[row][col] = sc.nextInt();
            }
        }

        for(int row = 0; row < n; row++) {
            for (int col = row + 1; col < n; col ++) {
                if (metric[row][col] == 1) {
                    union(row, col);
                }
            }
        }

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (i == parent[i]) {
                count++;
            }
        }

        System.out.println(count);
    }

    private static int find(int p) {
        while (p != parent[p]) {
            parent[p] = parent[parent[p]];
            p = parent[p];
        }

        return p;
    }

    private static void union(int p, int q) {
        int pRoot = find(p);
        int qRoot = find(q);
        if (pRoot != qRoot) {
            parent[pRoot] = qRoot;
        }
    }
}
